package com.example.csdn.mapper;

import com.example.csdn.pojo.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {

    @Select("select * from user where username = #{username}")
    User findByUserName(String username);

    //当Mapper方法接收一个对象参数时，MyBatis 会直接解包这个对象的属性,MyBatis会自动在 User 对象中查找同名属性
    //相当于调用 user.getUsername(), user.getPassword() 等
    @Insert("insert into user(username,password,create_time,identity,status)" +
            "values (#{username},#{password},now(),#{identity},#{status})")
    void add(User user);

    @Select("select * from user where id = #{userId}")
    User getUserInfo(Integer userId);

    @Update("update user set username = #{username}, email = #{email} where id = #{id}")
    void updateUserInfo(User user);

    @Update("update user set avatar = #{avatarURL} where id = #{userId}")
    void updateAvatar(String avatarURL, Integer userId);

    @Update("update user set password = #{newPwd} where id = #{id}")
    void updatePwd(String newPwd,Integer id);
}
